package com.gable.report.aop;

import org.apache.log4j.Logger;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Pointcut;

/**
 * Created by gable on 2018/8/22.
 */
/*@Component
@Aspect*/
public class DaoUsedTimeAspect {

    Logger logger = Logger.getLogger(DaoUsedTimeAspect.class);

    @Pointcut(value="execution(* com.gable.report.dao.*.*(..))")
    public void log(){}

    @Around("log()")
    public Object around(ProceedingJoinPoint pjp) throws Throwable {
        //方法执行之前获取当前时间
        long start = System.currentTimeMillis();
        String method =pjp.getSignature().toShortString();
        Object obj = null;
        try {
            obj = pjp.proceed();
        } catch (Throwable e) {
            logger.error(e);
            e.printStackTrace();
        }
        long end = System.currentTimeMillis();
        logger.info("--------------" + method + "执行了" + (end-start) + "毫秒"+ "------------------");
        return obj;
    }
}
